package org.example.config.sequence.configs.definition;

import org.example.config.sequence.configs.beans.MyImportBeanDefinitionRegistrarBean;
import org.example.config.sequence.inspect.Inspector;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * 通过{@link Import @Import}方式加载
 */
public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        Inspector.log(MyImportBeanDefinitionRegistrar.class, "registerBeanDefinitions");
        BeanDefinition beanDefinition = BeanDefinitionBuilder
                .genericBeanDefinition(MyImportBeanDefinitionRegistrarBean.class)
                .getBeanDefinition();
        registry.registerBeanDefinition(MyImportBeanDefinitionRegistrarBean.class.getSimpleName(), beanDefinition);
    }
}
